package serializable;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

class Animal implements Serializable{}
class Cat extends Animal{}
class Dog extends Animal{}
class Pig extends Animal{}
class Bird extends Animal{}
/*
如果一个List里面放了一堆对象,问题整个集合要序列化，那么？答案3
1.List要实现序列化   
2.元素要实现序列化   
3.List和元素要实现序列化
*/
public class SerializableDemo {
	public static void main(String[] args) throws IOException {
		List<Animal> list = new ArrayList<>();
		list.add(new Cat());
		list.add(new Dog());
		list.add(new Pig());
		list.add(new Bird());
		
		FileOutputStream fos = new FileOutputStream("animal.txt");
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(list);
		oos.flush();
		oos.close();
		fos.close();
	}
}
